/*
 * Copyright (c) 2011  Cristian Constantin
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.quizio.engine.model;

import com.quizio.engine.model.context.Views;
import org.codehaus.jackson.map.annotate.JsonView;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author Cristian Constantin
 * @since 10/16/11
 */
@Entity
@Table(name = "quizzes")
public class Quiz implements Serializable {

    private Long id;

    @JsonView(Views.Editor.class)
    private List<Question> questions;

    private String name;

    /**
     * The time limit for the quiz, in seconds.
     * A value of 0 represents no limit.
     */
    private Long maxDuration;

    @Id
    @SequenceGenerator(name = "quizzes_pk_sequence", sequenceName = "quizzes_id_seq")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "quizzes_pk_sequence")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "quiz")
    @Cascade(CascadeType.ALL)
    @OrderBy("id")
    public List<Question> getQuestions() {
        return questions;
    }

    public void setQuestions(List<Question> questions) {
        this.questions = questions;
    }

    @Column
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "max_duration", nullable = false)
    public Long getMaxDuration() {
        return maxDuration;
    }

    public void setMaxDuration(Long maxDuration) {
        this.maxDuration = maxDuration;
    }
}
